/**
 * Created by 烈日影视 on 2018/3/23.
 */
//$(function () {

var $goods_id, $uid, token, address, oldStartDate, oldEndDate, serverid;

//areaDetailAjax(55, "1C57D351-6D36-0357-EC7F-F6E8426302E5");

//getId();
//});
var isMobile = ismobile();

function WebViewDidFinishLoad() {

    var message = {

        "VcWay": "SendId"
    };

    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);
}

if (isMobile == 0) {

    window.android.getAndroidId("ok");
}

function ismobile() {
    //判断访问终端
    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
                weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
                qq: u.match(/\sQQ/i) == " qq" //是否QQ
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };

    if (browser.versions.mobile == true) {
        if (browser.versions.iPhone == true) {
            return '1';
        } else if (browser.versions.android == true) {
            return '0';
        }
    } else {

    }
}


function getId() {

    if (isMobile == 1) {

        CallSiteDetailsModel.jsCallOCWithSendId();

    } else if (isMobile == 0) {

        window.android.getAndroidId("ok");
    }
}

function receiveAndroidDetail(i) {//以后将uid直接传进areaDetailAjax（）去

    var obj = $.parseJSON(i);

    address = obj.addressID;

    token = obj.TOKEN;

    oldStartDate = obj.startDate;

    oldEndDate = obj.endDate;

    $goods_id = obj.goods_id;

    $uid = obj.uid;


    serviceId($goods_id, token, address, oldStartDate, oldEndDate)

}

function receiveiOSVcData(i) {

    var obj = $.parseJSON(i);

    //console.log(obj)

    address = obj.addressID;

    token = obj.TOKEN;

    //alert(token)

    oldStartDate = obj.startDate;

    oldEndDate = obj.endDate;

    $goods_id = obj.goods_id;

    $uid = obj.uid;

    serviceId($goods_id, token, address, oldStartDate, oldEndDate)
}

//获取场地服务商
function serviceId(goods_id, token, address, oldStartTime, oldEndTime) {

    $.ajax({

        type: "POST",

        url: url + "users/personservice",

        dataType: "json",

        //async: "false",

        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);

        },
        data: {
            "goods_id": goods_id
        },

        success: function (data) {

            //console.log(data)

            if (data.codes == 200) {

                serverid = data.data.service_id;

            } else {

                serverid = null;
            }

            areaDetailAjax(goods_id, token, address, oldStartTime, oldEndTime)

        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }
    });
}

function areaDetailAjax(goods_id, token, address, oldStartDate, oldEndDate) {

    $.ajax({

        type: "POST",

        url: url + "common",

        dataType: "json",

        data: {

            "goods_id": goods_id

        },
        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);

            xhr.setRequestHeader("CUSTOM-URL", "v1/product/goods/webInfo");

        },

        success: function (result) {

            //console.log(result.data.shop_price);

            if (result.codes == 200) {

                if (result.data.goods_tag.length > 3) {

                    result.data.goods_tag.length = 3
                }

                result.data.enterprise_info.start_time = result.data.enterprise_info.start_time.slice(0, 2) + ":" + result.data.enterprise_info.start_time.slice(2);

                result.data.enterprise_info.end_time = result.data.enterprise_info.end_time.slice(0, 2) + ":" + result.data.enterprise_info.end_time.slice(2);


                var html = template("areaDetailTpl", result);

                $("body").html(html);

                if (isiphoneX) {

                    $("#footer").css("padding-bottom", "0.484rem");

                    $(".remark").css("margin-bottom", "2.384rem")

                }

                if (oldStartDate && oldEndDate) {

                    $(".date .startDate").val(timeFormat(oldStartDate));

                    $(".date .endDate").val(timeFormat(oldEndDate));

                }

                getParams();

                isCollect($uid, $goods_id, token);

            }
            //轮播
            new Swiper('.swiper-container', {

                direction: 'horizontal',

                loop: true,

                autoplay: 4000,

                // 如果需要分页器

                pagination: '.swiper-pagination',

                autoplayDisableOnInteraction: false

            });

            if (result.data.goods_meal) {

                if (result.data.goods_meal[0].store_status == 100) {

                    $(".setMeal").find("li").eq(0).addClass("active");//默认第一项有active类   套餐

                }
                result.data.goods_meal.forEach(function (item, i) {

                    if (item.store_status == 200) {

                        $(".setMeal").find("li").eq(i).addClass("op");
                    }
                });
                if (result.data.goods_meal.length > 3) {

                    $(".meal>span").css("width", "1.7rem")
                }
            }


            $(".setMeal").on("click", "li", function () {//套餐

                $(".setMeal li").removeClass("active");

                $(this).addClass("active");

                var type = $(".setMeal li.active").attr("data-type");

                var worth = $(".setMeal li.active").attr("data-worth");

                getParams();

                $(".pprice  span").html(type);

                //$(".express_worth").html("押金：" + worth);

            });


            //点击开始时间按钮，获取ios和Android的信息
            $(".date").on("click", ".startDate", function () {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({"VcWay": "StartDate"});

                } else if (isMobile == 0) {

                    window.android.startShowToast("ok");
                }
            });
            //点击结束时间按钮，获取ios和Android的信息
            $(".date").on("click", ".endDate", function () {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({"VcWay": "EndDate"});

                } else if (isMobile == 0) {

                    window.android.endShowToast("ok");
                }
            });


            //点击立即购买跳转至下订单页
            if (serverid != null) {

                var isRun = true;

                $(".button").on("click", function () {

                    if (isRun) {

                        runa();

                        isRun = false;

                    }
                    setTimeout(function () {

                        isRun = true;

                    }, 1500);//点击后相隔多长时间可执行

                });

            } else {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": "没有相应供应商",
                        "VcWay": "ShowMessage"
                    });
                } else if (isMobile == 0) {

                    window.android.toastMsg("没有相应供应商");
                }

            }


            //点击产品信息跳转至产品信息页 【没有写通知ios和安卓回传参数的方法】
            $(".msg").on("click", function () {

                var json = {"goods_id": $goods_id};

                if (isMobile == 1) {

                    var message = {

                        "VcData": json,

                        "VcName": "SiteInformation",

                        "VcWay": "PushVCName"
                    };

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);


                } else if (isMobile == 0) {

                    window.android.jumpToProjectMsg(JSON.stringify(json));
                }
            });
            //点击累计评价跳转至累计评价页 【vcname是否正确】
            $(".appraise").on("click", function () {

                var json = {"goods_id": $goods_id};

                if (!json.goods_id)return false;

                if (isMobile == 1) {

                    var message = {

                        "VcData": json,

                        "VcName": "SiteEvaluation",

                        "VcWay": "PushVCName"
                    };

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);


                } else if (isMobile == 0) {

                    window.android.jumpToAppraise(JSON.stringify(json));

                }
            });
            //点击收藏，再次点击取消收藏
            $("#heart").on("touchstart", function () {

                var className = $(this).attr("class");

                //alert(className)

                if (className == "heart") {//如果是未收藏 点击就收藏 告诉后台

                    collect($uid, $goods_id, 100, $(this), token)

                } else if (className == "heartHover") {//已收藏，点击就取消收藏 告诉后台

                    collect($uid, $goods_id, 200, $(this), token)
                }
            });
            //点击购物车，弹出小黑框添加成功
            $(".cart").on("touchstart", function () {

                //var num22 = 1;

                var StartTime = $(".startDate").val().replace(/-/g, "/");

                var EndTime = $(".endDate").val().replace(/-/g, "/");

                var sumTotal = $(".sub").html();

                var goodsPrice = $(".setMeal li.active").data("type") || sumTotal;

                var meal = $(".setMeal li.active").attr("id") || 0;

                var addr = address;

                var timestampStart = Date.parse(new Date(StartTime)) / 1000;//开始时间    时间戳

                var timestampEnd = Date.parse(new Date(EndTime)) / 1000;    //结束时间    时间戳

                var timestampNow = Date.parse(new Date()) / 1000;          //当前时间     时间戳


                //开始时间要大于当前时间  结束时间只能大于开始时间小于3个月

                var timeLag = timestampEnd - timestampStart;

                var timeDistance = (mGetDate(1) + mGetDate(2) + mGetDate(3)) * 24 * 60 * 60;

                if (timeFormatDate(StartTime) && timeFormatDate(EndTime)) {

                    if (StartTime == "开始时间" || EndTime == "结束时间") {

                        if (StartTime == "开始时间") {

                            if (isMobile == 1) {

                                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                                    "VcData": "请选择开始时间",
                                    "VcWay": "ShowMessage"
                                });

                                //CallSiteDetailsModel.jsCalliOSWithShowMessage("请选择开始时间");

                            } else if (isMobile == 0) {

                                window.android.toastMsg("请选择开始时间");
                            }
                            return false;
                        }
                        if (EndTime == "结束时间") {

                            if (isMobile == 1) {

                                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                                    "VcData": "请选择结束时间",
                                    "VcWay": "ShowMessage"
                                });

                                //CallSiteDetailsModel.jsCalliOSWithShowMessage("请选择结束时间");

                            } else if (isMobile == 0) {

                                window.android.toastMsg("请选择结束时间");
                            }
                            return false;
                        }
                    } else if (StartTime >= EndTime) {

                        if (isMobile == 1) {

                            window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                                "VcData": "结束时间必须大于开始时间",
                                "VcWay": "ShowMessage"
                            });

                            //CallSiteDetailsModel.jsCalliOSWithShowMessage("结束时间必须大于开始时间");

                        } else if (isMobile == 0) {

                            window.android.toastMsg("结束时间必须大于开始时间");

                        }
                        return false;

                    } else if (timeLag > timeDistance) {

                        if (isMobile == 1) {

                            window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                                "VcData": "结束时间不能大于开始时间的90天",
                                "VcWay": "ShowMessage"
                            });

                            //CallSiteDetailsModel.jsCalliOSWithShowMessage("结束时间不能大于开始时间的90天");

                        } else if (isMobile == 0) {

                            window.android.toastMsg("结束时间不能大于开始时间的90天");
                        }
                        return false;
                    }
                    else {

                        addCar($uid, $goods_id, 1, timeFormatDate(StartTime), timeFormatDate(EndTime), goodsPrice, sumTotal.slice(1), meal, addr, token)
                    }
                }

            });

            $(".dangqi").on("click", function () {

                if (serverid != null) {

                    var json = {"goods_id": $goods_id, "uid": $uid, "uu_number": 1, "serverid": serverid};

                    if (isMobile == 1) {

                        var message = {

                            "VcData": json,

                            "VcName": "SiteCalender",

                            "VcWay": "PushVCName"
                        };

                        window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);

                    } else if (isMobile == 0) {

                        window.android.jumpToFieldCalader(JSON.stringify(json))
                    }
                } else {

                    if (isMobile == 1) {

                        window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                            "VcData": "没有相应供应商",
                            "VcWay": "ShowMessage"
                        });

                    } else if (isMobile == 0) {

                        window.android.toastMsg("没有相应供应商");
                    }
                }


            })

        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }
    })
}

//将判断库存的参数写在构造函数中
function Check(uid, goods_id, need_number, need_addr, meal_id, mealType, start_time, end_time) {

    this.uid = uid;

    this.goods_id = goods_id;

    this.need_address_id = need_addr;

    this.need_number = need_number;

    this.start_time = start_time;

    this.end_time = end_time;

    this.meal_id = meal_id;

    this.meal_type = mealType;

}
//检测是否有库存  点击立即购买订单判断，如果没有库存不能提交
function isCheck(data_json, token) {

    //console.log(data_json.need_address_id)

    $.ajax({

        type: "POST",

        url: url + "users/goodsstock",

        data: data_json,

        dataType: "json",

        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);

        },
        success: function (data) {

            if (data.codes != 200) {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": data.msg,
                        "VcWay": "ShowMessage"
                    });

                } else if (isMobile == 0) {

                    window.android.toastMsg(data.msg);
                }
            } else {

                var json = {

                    "need_addr": data_json.need_address_id,

                    "uid": $uid,

                    "goods_id": Number($goods_id),

                    "meal": {

                        "name": $.trim($(".setMeal li.active").html()),

                        "data_type": $(".setMeal li.active").data("type"),//套餐价格

                        "id": $(".setMeal li.active").attr("id"),

                        "mealType": $(".setMeal li.active").data("mealtype"),

                        "goods_worth": $(".setMeal li.active").data("worth")//套餐押金
                    },
                    "startTime": $(".startDate").val(),

                    "endTime": $(".endDate").val(),

                    "number": 1,

                    "money": $(".sub").html(),

                    "TOKEN": token
                };
                if (isMobile == 1) {

                    var message = {

                        "VcData": json,

                        "VcName": "SiteList",

                        "VcWay": "PushVCName"
                    };

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);

                } else if (isMobile == 0) {

                    window.android.jumpToProjectOrder(JSON.stringify(json));
                }
            }

            //}
        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }
    })
}

//点击开始时间和结束时间
var startDate;
function receiveiOSStartDate(a) {

    startDate = $(".startDate").val(a);

    getParams()
}
function receive_android_startDate(k) {

    startDate = $(".startDate").val(k);

    getParams()
}
var endDate;
function receiveiOSEndDate(a) {

    endDate = $(".endDate").val(a);

    getParams()
}
function receive_android_endDate(k) {

    endDate = $(".endDate").val(k);

    getParams()
}
//计算价格
function Amount(start_time, end_time, number, price) {

    var diffSecond = (end_time - start_time) / 1000;

    var diffHour = diffSecond / 3600;

    var diffDay = Math.floor(diffSecond / (24 * 3600));

    var remainderMoney = 0;

    if (diffHour > 24) {

        remainderHour = Math.ceil(diffHour % 24);

        if (remainderHour > 8) {

            diffDay += 1;

        } else {

            remainderMoney = (price / 8) * remainderHour;

        }
        return Number((diffDay * price + remainderMoney) * number).toFixed(2);

    } else {

        return Number(price * number).toFixed(2);
    }

}
//数量+ - 套餐  时间 放在一个类里面   时间要时间戳
function getParams() {

    var mealPrice = Number($(".setMeal li.active").data("type")) || Number($(".price").html());

    var startTime = $(".startDate").val();

    var endTime = $(".endDate").val();

    var num = 1;

    var timestamp1 = Date.parse(new Date(startTime.replace(/-/g, "/")));//将开始时间转换为时间戳

    var timestamp2 = Date.parse(new Date(endTime.replace(/-/g, "/")));//将结束时间转换为时间戳

    //console.log(mealPrice,startTime,endTime)

    if (timestamp1 && timestamp2) {

        var totalAmount = Amount(timestamp1, timestamp2, num, mealPrice);

        $(".sub").html("￥" + totalAmount)
    }

}
//格式化时间
function timeFormatDate(timeStamp) {

    var tmpTime = Date.parse(new Date(timeStamp));

    Date.prototype.format = function (format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    }

    var newDate = new Date();
    newDate.setTime(tmpTime);
    return newDate.format('yyyyMMddhhmm');
}
//格式化时间
function timeFormat(time) {//201712271200
    var y = time.substring(0, 4);
    var m = time.substring(4, 6);
    var d = time.substring(6, 8);
    var h = time.substring(8, 10);
    var s = time.substring(10, 12);
    return (y + "-" + m + "-" + d + " " + h + ":" + s)
}
//判断是否已收藏
function isCollect(uid, goods_id, token) {
    $.ajax({

        type: "POST",

        url: url + "users/goodsjudge",

        datType: "json",

        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);
        },
        data: {
            uid: uid,

            goods_id: goods_id
        },
        success: function (data) {

            if (data.data.codes == "200") {//已收藏

                $("#heart").removeClass("heart").addClass("heartHover");

                $(".footer_tit").html("已收藏")

            } else {//未收藏

                $("#heart").removeClass("heartHover").addClass("heart");

                $(".footer_tit").html("收藏")
            }
        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

                //CallSiteDetailsModel.jsCalliOSWithShowMessage("请检查网络");

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }
    })
}
//收藏和取消收藏
function collect(uid, goods_id, number, that, token) {

    $.ajax({

        type: "POST",

        url: url + "users/productcollect",

        dataType: "json",

        //async: "false",

        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);
        },
        data: {
            uid: uid,

            goods_id: goods_id,

            status: number
        },

        success: function (data) {

            //console.log(data)

            if (data.codes == 200) {

                if (number == 200) {

                    that.removeClass("heartHover").addClass('heart');

                    $(".footer_tit").html("收藏");

                    if (isMobile == 1) {

                        window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                            "VcData": "取消收藏",
                            "VcWay": "ShowMessage"
                        });

                        //CallSiteDetailsModel.jsCalliOSWithShowMessage("取消收藏");

                    } else if (isMobile == 0) {

                        window.android.toastMsg("取消收藏");
                    }
                } else if (number == 100) {

                    //$(".container").addClass("opacity");

                    $(".modelBox").show();

                    $(".collection").show();

                    $(".collection .ok").click(function () {

                        $("#heart").attr("class", "heartHover");

                        $(".footer_tit").html("已收藏");

                        $(".collection").hide();

                        $(".modelBox").hide();

                        //$(".container").removeClass("opacity");
                    });

                }

            } else {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": "收藏失败",
                        "VcWay": "ShowMessage"
                    });

                    //CallSiteDetailsModel.jsCalliOSWithShowMessage("收藏失败");

                } else if (isMobile == 0) {

                    window.android.toastMsg("收藏失败");
                }

            }
        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

                //CallSiteDetailsModel.jsCalliOSWithShowMessage("请检查网络");

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }
    })
}
//加入购物车
function addCar(uid, goods_id, goods_number, start_time, end_time, goods_price, sum_total, meal_id, need_addr, token) {
    $.ajax({

        type: "POST",

        url: url + "users/addcart",

        dataType: "json",

        data: {

            "uid": uid,

            "goods_id": goods_id,

            "goods_number": goods_number,

            "start_time": start_time,

            "end_time": end_time,

            "goods_price": goods_price,

            "sum_total": sum_total,

            "meal_id": meal_id,

            "need_addr_id": need_addr

            //"need_addr_id": 110101
        },
        beforeSend: function (xhr) {

            xhr.setRequestHeader("TOKEN", token);
        },
        success: function (data) {

            //console.log(data)

            if (data.codes == 200) {

                if (isMobile == 1) {

                    //CallSiteDetailsModel.jsCalliOSWithAddDetails();
                    //
                    //CallSiteDetailsModel.jsCalliOSWithShowMessage("加入清单成功");


                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({"VcWay": "AddDetails"});

                    var message = {

                        "VcData": "加入清单成功",

                        "VcWay": "ShowMessage"
                    };

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage(message);

                } else if (isMobile == 0) {

                    window.android.addShopCarSuccess("ok");

                    window.android.toastMsg("加入清单成功");
                }
            } else {
                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": "加入清单失败",
                        "VcWay": "ShowMessage"
                    });

                    //CallSiteDetailsModel.jsCalliOSWithShowMessage("加入清单失败");

                } else if (isMobile == 0) {

                    window.android.toastMsg("加入清单失败");
                }
            }

        },
        error: function (info) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "请检查网络",
                    "VcWay": "ShowMessage"
                });

                //CallSiteDetailsModel.jsCalliOSWithShowMessage("请检查网络");

            } else if (isMobile == 0) {

                window.android.toastMsg("请检查网络");
            }
        }

    })
}
function runa() {

    var time1 = $('.startDate').val();

    var time2 = $('.endDate').val();

    var mealId = $(".setMeal li.active").attr("id");

    var timestamp = Date.parse(new Date());//当前时间时间戳

    if (timeFormatDate(time1.replace(/-/g, "/")) && timeFormatDate(time2.replace(/-/g, "/"))) {

        if (time1 == "开始时间" || time2 == "结束时间") {

            if (time1 == "开始时间") {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": "请选择开始时间",
                        "VcWay": "ShowMessage"
                    });
                    //CallSiteDetailsModel.jsCalliOSWithShowMessage("请选择开始时间");

                } else if (isMobile == 0) {

                    window.android.toastMsg("请选择开始时间");
                }
                return false;
            }
            if (time2 == "结束时间") {

                if (isMobile == 1) {

                    window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                        "VcData": "请选择结束时间",
                        "VcWay": "ShowMessage"
                    });

                    //CallSiteDetailsModel.jsCalliOSWithShowMessage("请选择结束时间");

                } else if (isMobile == 0) {

                    window.android.toastMsg("请选择结束时间");
                }
                return false;
            }
        } else if (time1 >= time2) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "结束时间必须大于开始时间",
                    "VcWay": "ShowMessage"
                });

                //CallSiteDetailsModel.jsCalliOSWithShowMessage("结束时间必须大于开始时间");

            } else if (isMobile == 0) {

                window.android.toastMsg("结束时间必须大于开始时间");
            }
            return false;
        }
        else if (new Date(time1.replace(/-/g, "/")).getTime() < timestamp) {

            if (isMobile == 1) {

                window.webkit.messageHandlers.CallSiteDetailsModel.postMessage({
                    "VcData": "开始时间必须大于当前时间",
                    "VcWay": "ShowMessage"
                });

                //CallSiteDetailsModel.jsCalliOSWithShowMessage("开始时间必须大于当前时间");

            } else if (isMobile == 0) {

                window.android.toastMsg("开始时间必须大于当前时间");
            }
            return false;
        }
        else {
            var check = new Check($uid, $goods_id, 1, address, mealId, $(".setMeal li.active").data("mealtype"), String(timeFormatDate(time1.replace(/-/g, "/"))), String(timeFormatDate(time2.replace(/-/g, "/"))));

            isCheck(check, token);//点击的时候先检测库存
        }
    }

}
//这个方法是安卓和ios调用，收藏页面点击条目进入详情  判断是否为收藏状态
function changeCollectStatus(k) {

    //console.log('移动端发送数据'+JSON.stringify(k));

    //if (isMobile == 0) {

    var obj = $.parseJSON(k);

    isCollect(obj.uid, obj.goods_id, obj.TOKEN);

    //} else if (isMobile == 1) {
    //
    //    isCollect(k.uid, k.goods_id, k.TOKEN);
    //}
}
//获取当前月的天数，下月，下下月的总和
function mGetDate(n) {

    var date = new Date();

    var year = date.getFullYear();

    var month = date.getMonth() + n;

    if (month > 12) {

        year++;

        month = month - 12;
    }
    var d = new Date(year, month, 0);

    return d.getDate();
}


